package com.glsc.ngateway.common.base.domain.mysql.gateway.oaflow;

import com.glsc.ngateway.common.base.domain.mysql.BaseEntity;
import com.glsc.ngateway.common.base.enums.OaFlowSyncLogStatusEnum;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Table;

/**
 * oa同步自研网关记录实体类
 * @author xuchang
 */
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@Entity
@Where(clause = "deleted = 0")
@SQLDelete(sql = "update t_oa_flow_sync_log set deleted = UNIX_TIMESTAMP(NOW()), handled = 0 where id=?")
@SQLDeleteAll(sql = "update t_oa_flow_sync_log set deleted = UNIX_TIMESTAMP(NOW()), handled = 0 where id=?")
@Table(name = "t_oa_flow_sync_log", indexes = {@Index(name = "UK_TASK_WORKFLOW", columnList = "workflow_id, task_id, deleted", unique = true)})
public class TOaFlowSyncLog extends BaseEntity {
    private static final long serialVersionUID = -2758136986172189360L;

    @Column(name = "request_Id", columnDefinition = "bigint comment '同步id'")
    private Integer requestId;

    @Column(name = "workflow_id", columnDefinition = "varchar(128) not null comment 'workflow id'")
    private String workflowId;

    @Column(name = "process_def_key", columnDefinition = "varchar(128) not null comment '流程定义key'")
    private String processDefKey;

    @Column(name = "task_def_key", columnDefinition = "varchar(128) not null comment '节点定义key'")
    private String taskDefKey;

    @Column(name = "process_id", columnDefinition = "varchar(128) not null comment '流程实例id'")
    private String processId;

    @Column(name = "task_id", columnDefinition = "varchar(128) not null comment '节点实例id'")
    private String taskId;

    @Column(name = "applicant", columnDefinition = "varchar(128) not null comment '申请人'")
    private String applicant;

    @Column(name = "approved", columnDefinition = "varchar(128) not null comment '审批人'")
    private String approved;

    @Column(name = "form_data", columnDefinition = "text not null comment '表单数据'")
    private String formData;

    @Builder.Default
    @Column(name = "status", columnDefinition = "varchar(32) not null comment '状态'")
    private String status = OaFlowSyncLogStatusEnum.UNSYNC.getCode();
}
